<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>留言板</title>
	<style type="text/css">
		*{
			margin: 0px;
			padding: 0px;
		}
		h2{
			text-align: center;
		}
		table{
			margin: 0 auto;
		}
		div{
			margin: 0 auto;
			width: 430px;

		}
			.item{
				margin-top:10px;
				border:1px solid #ccc;
			}
			.name{
				background: #cccccc;
			}
			.time{
				border-top: 1px solid #cccccc;
				margin-bottom:5px; 
				text-align: right;
			}
			a{
				text-decoration: none;
				color: green;
				float: right;
		}
	</style>
</head>
<body>
	<h2>吴松的留言板</h2>
	<form method="post" action="add.php">
	<table>
		<tr>
			<td>姓名</td>
			<td><input type="text" name="name" value="" style="width:400px; height:20px; "></td>
		</tr>
		<tr>
			<td>内容</td>
			<td><textarea style=" width:400px; " rows="5" name="write"></textarea></td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" /></td>
		</tr>
	</table>
	</form>
<?php
	error_reporting(E_ERROR | E_WARNING | E_PARSE);
	$conn = mysql_connect("127.0.0.1","root","");
	if (!$conn) {
		echo "链接错误";
		exit();
	}
	if (!mysql_query("use messageboard",$conn)) {
		echo "数据库链接失败";
		exit();
	}
	mysql_query("set names utf8",$conn);
	$resourse = mysql_query("select * from data",$conn);  
	$data = array();
	while ($row = mysql_fetch_row($resourse)){
		$data[] = $row;
	}

	$i=0;
	foreach ($data as $value) {
		if ($value!=null) {	
?>
	<div class="item">
		<div class="name">
			留言人：<b><?php echo $value[1]?></b>
			<a href="edit.php?id=<?php echo $value[0]?>">编辑</a>
			<a href="del.php?id=<?php echo $value[0]?>">删除&nbsp;</a>
		</div>
		<div><?php echo $value[2]?></div>
		<div class="time">留言时间：<?php echo date("Y-m-d H:i:s",$value[3])?></div>
	</div>
<?php
		}
	$i++;
	}
?>
</body>
</html>